<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>雇员信息列表及分页</title>
</head>
<?php 

	$link=mysqli_connect('localhost','root','');
	mysqli_query($link,"set names = utf8;") ;
	mysqli_query($link,'use empManage;');

	$pageNow=1;  //默认第一页
	$rowCount=0;  //共有多少条数据 需查询
	$pageSize=6;  //每行显示多少条数据 自己设定

	if (!empty($_GET['pageNow'])) {
		$pageNow=$_GET['pageNow'];
	}

	$sql='select count(id) from emp';
	$res1=mysqli_query($link,$sql);
	if ($row=mysqli_fetch_row($res1)) {
		$rowCount=$row[0];
	}
	$pageCount=ceil($rowCount/$pageSize);




	$sql='select * from emp limit '.($pageNow-1)*$pageSize.','.$pageSize.';';
	$res2=mysqli_query($link,$sql);

	echo "<h1>雇员信息列表</h1>";
	echo "<table border='1px' width='700px' cellspacing='0px' >";
	echo "<tr><th>id</th><th>name</th><th>grade</th><th>email</th><th>salary</th><th>删除用户</th><th>修改用户</th></tr>";

	while ($row=mysqli_fetch_assoc($res2)) {
		echo "<tr align='center'><td>".$row['id']."</td><td>".$row['name']."</td><td>".
		$row['grade']."</td><td>".$row['email']."</td><td>".$row['salary']
		."</td><td><a href='#'>删除用户</a></td><td><a href='#'>修改用户</a></td></tr>";
	}
	echo "</table>";
	/*for ($i=1; $i<=$pageCount ; $i++) { 
		echo "<a href='empList.php?pageNow=".$i."'>".$i." &nbsp;</a>";
	}*/

	if ($pageNow>1) {
		$prePage=$pageNow-1;
		echo "<a href='empList.php?pageNow=".$prePage."'>上一页 &nbsp; </a>";
	}
	if ($pageNow<$pageCount) {
		$nextPage=$pageNow+1;
		echo "<a href='empList.php?pageNow=".$nextPage."'>下一页 &nbsp;</a>";
	}
	/*echo "<a href='#'><<< &nbsp; </a>";
	echo "<a href='#'>[".$pageNow."]</a>";
	echo "<a href='#'>[".$pageNow+1."]</a>";
	echo "<a href='#'>[".$pageNow+2."]</a>";
	echo "<a href='#'>[".$pageNow+3."]</a>";
	echo "<a href='#'>[".$pageNow+4."] &nbsp; </a>";
	echo "<a href='#'>>></a>";*/
	echo "当前第".$pageNow."页/共".$pageCount."页";
	echo "<br /> <br />";
	echo "<form action='empList.php'>";
	echo "跳转到：<input type='text' name='pageNow'>
			     <input type='submit' value='GO'>";



	

	

?>
<body>





	
</body>
</html>